using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.CodeSetup
{
    /// <summary>
    /// author:Weiyudong
    /// </summary>
    public partial class FireLinkEntry : BasePage_SOM
    {
        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140811";
            }
        }

        #endregion

        #region Page Init And Load

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(FireLinkEntry_ChangeLanguage);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.TracePageChange = true;//alert when change page.

            if (!IsPostBack)
            {
                SetLanguage();
                InitPage();
            }
            else
            {
                this.IsServerChanged = true;
            }
        }

        /// <summary>
        /// BindStation
        /// add by gordon 20151102 U273
        /// </summary>
        private void BindStation()
        {
            if (DAL.Security.User.CanFunctionItemAccess("M140811_F1", this.ODMUser.UserProfileID, this.MenuID))//access all station.
            {
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), this.ODMUser.LocationID), false);
                this.ddlStation.Enabled = true;
            }
            else if (DAL.Security.User.CanFunctionItemAccess("M140811_F3", this.ODMUser.UserProfileID, this.MenuID))//Can Access other stations.
            {
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.LocationID), false);
                this.ddlStation.Enabled = true;
            }
            else
            {
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.LocationID), false);
                this.ddlStation.Enabled = false;
            }

            this.FindByValueAndSelect(ddlStation, this.ODMUser.LocationID.ToString());
            ddlStation_SelectedIndexChanged(null,null);
        }


        private void InitPage()
        {
            //add by gordon 20151102 U273
            BindStation();

            //remove by gordon 20151102 U273
            //string CanAccessAllStation = string.Empty;
            ////init location list
            ////BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, CanAccessAllStation, Convert.ToInt16(LangCode), this.ODMUser.StationID), true, "-1");
            //BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, CanAccessAllStation, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true, "-1");
            //// edit by dylan 20151009 for u233
            ////this.ddlLocation.Enabled = false;
         
            //if (DAL.Security.User.CanFunctionItemAccess("M140811_F3", this.ODMUser.UserProfileID, this.MenuID))//Can Access other stations.
            //{
            //    CanAccessAllStation = "0";
            //    //BindStation
            //    //BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, CanAccessAllStation, Convert.ToInt16(LangCode), this.ODMUser.StationID), true, "-1");
            //    BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, CanAccessAllStation, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true, "-1");
            //    this.ddlLocation.Enabled = true;
            //}
            //if (DAL.Security.User.CanFunctionItemAccess("M140811_F1", this.ODMUser.UserProfileID, this.MenuID))//access all station.
            //{
            //    CanAccessAllStation = "1";
            //    //BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, CanAccessAllStation, Convert.ToInt16(LangCode), this.ODMUser.StationID), true, "-1");
            //    BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, CanAccessAllStation, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true, "-1");
            //    this.ddlLocation.Enabled = true;
            //}

            // add by dylan 20150626 for u82
            BindListControl(this.ddlLine, "LineId", "LineCode", DAL.SOM.CodeSetup.CDFireLink.GetAllSOMLines(Convert.ToInt32(LangCode)), true, "-1");


            if (DAL.Security.User.CanFunctionItemAccess("M140811_F2", this.ODMUser.UserProfileID, this.MenuID))//readonly
            {
                DisableAllControls();
            }
            //else
            //{
            //    BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessLocationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode)), true, "-1");
            //    this.ddlLocation.Enabled = false;
            //}

            //remove by gordon 20151102 U273
            //if (this.ddlLocation.Items.Count == 0)
            //{

            //    return;
            //}

            //remove by gordon 20151102 U273
            ////add by gordon 20150713 U116
            //this.FindByValueAndSelect(ddlLocation, this.ODMUser.LocationID.ToString());
            //ddlLocation_SelectedIndexChanged(null,null);

            //check is it from edit or new                      
            if (Request.QueryString["FireLinkID"] != null && Request.QueryString["action"].ToUpper() == "EDIT")//Edit
            {
                //if the record is existed, init the page
                DataTable DTable = DAL.SOM.CodeSetup.CDFireLink.GetFireLinkDetailByID(Convert.ToInt32(Request.QueryString["FireLinkID"]), this.LangCode);

                if (DTable == null || DTable.Rows.Count == 0)
                {
                    return;
                }

                //add by gordon 20151102 U273
                if (this.ddlStation.Items.FindByValue(DTable.Rows[0]["LocationID"].ToString()) != null)
                {
                    this.FindByValueAndSelect(ddlStation, DTable.Rows[0]["LocationID"].ToString());
                }
                this.ddlStation.Enabled = false;

                //modify by tim 20160202 Location bind error
                BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, "", Convert.ToInt16(LangCode), Convert.ToInt32(ddlStation.SelectedValue)), true, "-1");

                if (this.ddlLocation.Items.FindByValue(DTable.Rows[0]["ancillaryLocationID"].ToString()) != null)
                {
                    //this.ddlLocation.SelectedValue = DTable.Rows[0]["ancillaryLocationID"].ToString();
                    this.FindByValueAndSelect(ddlLocation, DTable.Rows[0]["ancillaryLocationID"].ToString());
                }
                //update by gordon 20160128 ISU31
                //this.ddlLocation.Enabled = false;
                this.ddlLocation.Enabled = true;
                //update end by gordon 20160128 ISU31

                // add by dylan 20150626 for u82
                if (this.ddlLine.Items.FindByValue(DTable.Rows[0]["LineId"].ToString()) != null)
                {
                    this.FindByValueAndSelect(ddlLine, DTable.Rows[0]["LineId"].ToString());
                }
                //this.ddlLocation.Enabled = false;//remove by gordon 20160128 ISU31

                this.hdnFireLinkID.Value = Request.QueryString["FireLinkID"];
                this.txtCode.Text = DTable.Rows[0]["code"].ToString();
                //on location changed
                //this.txtStation.Text = DTable.Rows[0]["StationCode"].ToString();//remove by gordon 20151030 U273
                this.txtFireLinkCode.Text = DTable.Rows[0]["FireLinkCode"].ToString();
                this.txtDetailLocation.Text = DTable.Rows[0]["DetailLocation"].ToString();
                this.txtSequenceNO.Text = DTable.Rows[0]["SeqNo"].ToString();
                this.dtbEffectiveFrom.SetDateTime(this.ConvertToDateTime(DTable.Rows[0]["EffectiveFrom"].ToString()));
                this.dtbEffectiveTo.SetDateTime(this.ConvertToDateTime(DTable.Rows[0]["EffectiveTo"].ToString()));

                this.hdnStationID.Value = DTable.Rows[0]["LocationID"].ToString();
                this.chkObsolete.Checked = DTable.Rows[0]["FlagObsolete"].ToString() == "False" ? false : true;

                if (DTable.Rows[0]["FlagObsolete"].ToString() == "True")
                {
                    DisableAllControls();
                }


                DTable.Dispose();
                DTable = null;

            }
            else if (Request.QueryString["action"] != null && Request.QueryString["action"].ToUpper() == "NEW")//New
            {
                //update by gordon 20151102 U273
                //if (!DAL.Security.User.CanFunctionItemAccess("M140811_F1", this.ODMUser.UserProfileID, this.MenuID) && !DAL.Security.User.CanFunctionItemAccess("M140811_F3", this.ODMUser.UserProfileID, this.MenuID))//access all station. or Can Access other stations.
                //{
                //    //update by gordon 20151021 U247
                //    //if (this.ddlLocation.Items.FindByValue(CurrentStation.ToString()) != null)
                //    //{
                //    //    this.ddlLocation.SelectedValue = this.CurrentStation.ToString();
                //    //}
                //    if (this.ddlLocation.Items.FindByValue(CurrentLocation.ToString()) != null)
                //    {
                //        this.ddlLocation.SelectedValue = this.CurrentLocation.ToString();
                //    }
                //}
                this.chkObsolete.Enabled = false;//It is display only.
                //this.onDdlLocationChanged();//remove by gordon 20151102 U273
                //this.btnVoid.Enabled = false;
            }
            else
            {
                Response.Redirect("FireLinkList.aspx");
            }
            //string bindScript = "if (confirm('" + this.GetMessage("SOM_VoidSure") + "') )";

            //bindScript = bindScript + "{return true;}";
            //bindScript = bindScript + "else";
            //bindScript = bindScript + "{return false;}";
            //bindScript = bindScript + "";

            //this.btnVoid.Attributes.Add("onclick", bindScript);
        }
        #endregion

        #region SetLanguage
        private void SetLanguage()
        {
            // this.lblCodeSetupTitle.Text = this.GetLabel("SOM_FireLinkEntryTitle");
            this.lblMenuCaption.Text = GetLabel("SOM_FireLink");
            this.lblCode.Text = GetLabel("Code", true);
            this.lblLocation.Text = GetLabel("SOM_Location", true);
            this.lblFireLinkCode.Text = GetLabel("SOM_FireLinkCode", true);
            this.lblStation.Text = GetLabel("SOM_Station", true);
            this.lblDetailLocation.Text = GetLabel("SOM_DetailLocation", true);
            this.lblSequenceNo.Text = GetLabel("SOM_SequenceNO", true);
            this.lblFrom.Text = GetLabel("SOM_EffectiveFrom", true);
            this.lblTo.Text = GetLabel("SOM_EffectiveTo", true);
            this.lblObsolete.Text = GetLabel("SOM_Void", true);

            // add by dylan 20150626 for u82
            this.lblLine.Text = GetLabel("SOM_Line", true);

            //this.btnSave.Text = GetLabel("COM_Save");
            ////this.btnCancel.Text = GetLabel("COM_Cancel");
            //this.btnNew.Text = GetLabel("SOM_NewFireLink");
            //this.btnVoid.Text = this.GetLabel("SOM_VoidOperation");
            this.btnSave.Text = GetLabel("COM_Save");
            this.btnSaveAndNew.Text = GetLabel("SOM_SaveNew");
            this.btnSaveAndReturn.Text = GetLabel("COM_SaveAndReturn");
            this.btnCancel.Text = GetLabel("COM_Cancel");
        }

        private void FireLinkEntry_ChangeLanguage(object sender, EventArgs e)
        {
            SetLanguage();
            if (IsPostBack)  //added by Huangyao 20090119
            {
                InitPage();
            }
        }
        #endregion

        #region Event

        /// <summary>
        /// ddlStation_SelectedIndexChanged
        /// add by gordon 20151030 U273
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlStation_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Change ddlLocation DataSource
            BindListControl(this.ddlLocation, "LocationID", "station", DAL.SOM.CodeSetup.CDFireLink.AccessFireLinkLocationWithUserID(this.ODMUser.ID, "", Convert.ToInt16(LangCode), Convert.ToInt32( ddlStation.SelectedValue)), true, "-1");

            this.hdnStationID.Value = ddlStation.SelectedValue;
        }

        /// <summary>
        /// txtDetailLocation_TextChangeds
        /// add by gordon 20151030 U273
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void txtDetailLocation_TextChangeds(object sender, EventArgs e)
        {
            string dlText = txtDetailLocation.Text;
            string code = txtCode.Text;

            if (CheckFireLinkCodeLength(dlText + " " + code))
            {
                txtFireLinkCode.Text = dlText + " " + code;
            }
            else
            {
                Alert(GetMessage("SOM_FireLinkCodeLength"));
            }
        }

        protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
        {
            //update by gordon 20151030 U273
            //this.onDdlLocationChanged();
            if (ddlLocation.Items.Count > 0)
            {
                txtDetailLocation.Text = ddlLocation.SelectedItem.Text;
                txtDetailLocation_TextChangeds(null,null);
            }

        }
        /// <summary>
        /// on location changed, reload the firelinkcode and txtstation info
        /// </summary>
        private void onDdlLocationChanged()
        {
            if (this.ddlLocation.Items.Count == 0 || this.ddlLocation.SelectedValue == "-1")
            {
                //this.Alert(this.GetMessage("SOM_LocationNotNull"));
                if (this.ddlLocation.SelectedValue == "-1")
                {
                    //this.txtStation.Text = "";//remove by gordon 20151030
                    this.hdnStationID.Value = "0";
                    //this.txtFireLinkCode.Text = "";
                }
                return;
            }
            this.txtFireLinkCode.Text = this.ddlLocation.SelectedItem.Text + ' ' + this.txtCode.Text;
            //add by gordon 20150713 U116
            this.txtDetailLocation.Text = this.ddlLocation.SelectedItem.Text;
            DataTable DTable = DAL.SOM.CodeSetup.CDFireLink.GetStationInfoByLocation(Convert.ToInt32(this.ddlLocation.SelectedValue), this.LangCode);
            if (DTable != null && DTable.Rows.Count > 0)
            {
                //this.txtStation.Text = DTable.Rows[0]["StationCode"].ToString();//remove by gordon 20151030
                this.hdnStationID.Value = DTable.Rows[0]["stationID"].ToString();

            }
            else//alert that the location should not be selected
            {
                //?
            }
        }


        protected void ddlLine_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        #region remove by gordon 20151117 - no longer use for U273
        ///// <summary>
        ///// on code changed, reload the firelinkcode
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void txtCode_TextChanged(object sender, EventArgs e)
        //{
        //    //update by gordon 20151030
        //    //if (this.ddlLocation.Items.Count == 0 || this.ddlLocation.SelectedValue == "-1")
        //    //{
        //    //    //this.Alert(this.GetMessage("SOM_LocationNotNull"));
        //    //    return;
        //    //}
        //    //this.txtFireLinkCode.Text = this.ddlLocation.SelectedItem.Text + ' ' + this.txtCode.Text;

        //    string dlText = txtDetailLocation.Text;
        //    string code = txtCode.Text;

        //    if (CheckFireLinkCodeLength(dlText + " " + code))
        //    {
        //        txtFireLinkCode.Text = dlText + " " + code;
        //    }
        //    else
        //    {
        //        Alert(GetMessage("SOM_FireLinkCodeLength"));
        //    }
        //}
        #endregion

        /// <summary>
        /// update,new operation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.dtbEffectiveFrom.Text.Trim().Length > 0 && this.dtbEffectiveTo.Text.Trim().Length > 0)
            {
                if (InvalidateInputDate(this.dtbEffectiveFrom.GetDateTime(), this.dtbEffectiveTo.GetDateTime()))
                {
                    Alert(this.GetMessage("COM_StartEndDate"));
                    return;
                }
            }
            this.UpdateRecord(1);
        }
        /// <summary>
        /// void the record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void btnVoid_Click(object sender, EventArgs e)
        //{
        //    this.chkObsolete.Checked = true;
        //    this.UpdateRecord();

        //}
        protected void chkObsolete_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chkObsolete.Checked)
            {
                string bindScript = "if (confirm('" + this.GetMessage("SOM_VoidSure") + "') )";

                bindScript = bindScript + "{return true;}";
                bindScript = bindScript + "else";
                bindScript = bindScript + "{return false;}";
                bindScript = bindScript + "";

                this.btnSave.Attributes.Add("onclick", bindScript);
                this.btnSaveAndNew.Attributes.Add("onclick", bindScript);
                this.btnSaveAndReturn.Attributes.Add("onclick", bindScript);
            }
            else
            {
                this.btnSave.Attributes.Clear();
                this.btnSaveAndReturn.Attributes.Clear();
                this.btnSaveAndNew.Attributes.Clear();
            }

        }
        #endregion

        #region self custom functions

        /// <summary>
        /// CheckFireLinkCodeLength
        /// add by gordon 20151030 U273
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        private bool CheckFireLinkCodeLength(string txt)
        {
            if (txt.Trim().Length > 25)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// new\update\void Record
        /// </summary>
        private void UpdateRecord(int type)
        {
            int mResult = 0;//default is failure state
            int fireLinkID = 0;
            try
            {
                int action = 0;

                if (this.chkObsolete.Checked)
                {
                    action = 3;
                    fireLinkID = Convert.ToInt32(this.hdnFireLinkID.Value);
                }
                else if (this.hdnFireLinkID.Value == "0")
                {
                    action = 1;
                }
                else
                {
                    action = 2;
                    fireLinkID = Convert.ToInt32(this.hdnFireLinkID.Value);
                }

                //add by gordon 20151030 U273
                if (ddlStation.Items.Count == 0 || ddlStation.SelectedValue == "-1")
                {
                    Alert(GetMessage("SOM_StationMandatory"));
                    return;
                }

                //check station: must exists in table SOM_CDStation
                //Gordon: U247 20151019 hdnStationID.Value is right
                if (!DAL.SOM.Event.StationEventDa.IsLegalStation(Convert.ToInt32(this.hdnStationID.Value)))
                {
                    //this.Alert("Current station is not an legal station for SOM");
                    this.Alert(this.GetMessage("SOM_LegalStationCheck"));
                    return;
                }

                string code = this.txtCode.Text.Trim();
                if (code == "")
                {
                    this.Alert(this.GetMessage("SOM_FireLink_Code"));
                    return;
                }

                if (string.IsNullOrEmpty(txtDetailLocation.Text.Trim()))
                {
                    Alert(GetMessage("SOM_DetailLocationMandatory"));
                    return;
                }

                if (string.IsNullOrEmpty(txtFireLinkCode.Text.Trim()))
                {
                    Alert(GetMessage("SOM_FireLinkCodeMandatory"));
                    return;
                }

             

                //remove by gordon 20151030 U273
                //if (this.ddlLocation.Items.Count == 0 || this.ddlLocation.SelectedValue == "-1")
                //{
                //    this.Alert(this.GetMessage("SOM_LocationNotNull"));
                //    return;
                //}

                if (this.txtSequenceNO.Text.Trim() == "")
                {
                    this.Alert(this.GetMessage("SOM_FireLinkSeqNo"));
                    return;
                }

                // add by dylan 20150626 for u82
                if (this.ddlLine.Items.Count == 0 || this.ddlLine.SelectedValue == "-1")
                {
                    this.Alert(this.GetMessage("SOM_LineNotNull"));
                    return;
                }

                if (this.dtbEffectiveFrom.Text.Trim() == String.Empty)
                {
                    this.Alert(this.GetMessage("SOM_FromTimeNotNull"));
                    return;
                }
                else if (this.dtbEffectiveTo.Text.Trim() == String.Empty)
                {
                    this.Alert(this.GetMessage("SOM_ToTimeNotNull"));
                    return;
                }
                if (InvalidateInputDate(this.dtbEffectiveFrom.GetDateTime(), this.dtbEffectiveTo.GetDateTime()))
                {
                    Alert(this.GetMessage("COM_StartEndDate"));
                    return;
                }
                int flagObsolete = this.chkObsolete.Checked == true ? 1 : 0;

                // add ddlLine parameter by dylan for u82
                mResult = DAL.SOM.CodeSetup.CDFireLink.UpdateFireLink(Convert.ToInt32(this.ddlLocation.SelectedValue), Convert.ToInt32(this.ddlLine.SelectedValue), Convert.ToInt32(this.hdnStationID.Value), code,
                          this.txtFireLinkCode.Text, this.txtDetailLocation.Text, Convert.ToInt16(this.txtSequenceNO.Text), flagObsolete, this.dtbEffectiveFrom.GetDateTime(),
                          this.dtbEffectiveTo.GetDateTime(), this.ODMUser.ID, this.ODMUser.ID, action, ref fireLinkID);

                if (mResult == 1)
                {
                    //new, update or absolete success
                    this.Alert(this.GetMessage("SaveSuccessfully"));
                    this.hdnFireLinkID.Value = fireLinkID.ToString();
                    if (type == 1)//save
                    {
                        //this.Response.Redirect("FireLinkEntry.aspx?action=edit&FireLinkID=" + fireLinkID);
                        //this.hdnFireLinkID.Value = fireLinkID.ToString();
                        //string script = "<script language=javascript>function btnChange_Click(){window.location.href='FireLinkEntry.aspx?action=edit&FireLinkID='" + fireLinkID+"'} window.setTimeout(btnChange_Click,50);" + "</script>";
                        //this.Page.RegisterStartupScript("aaa", script);
                        //update by gordon 20160128 ISU31
                        //this.ddlLocation.Enabled = false;
                        ddlLocation.Enabled = true;
                        //update end by gordon 20160128 ISU31
                        this.chkObsolete.Enabled = true;
                        //add by gordon 20151102 U273
                        ddlStation.Enabled = false;

                        if (action == 3)
                        {
                            DisableAllControls();
                        }
                    }
                    else if (type == 2)//save and return
                    {
                        string script = "<script language=javascript>function btnChange_Click(){window.location.href='FireLinkList.aspx'} window.setTimeout(btnChange_Click,150);" + "</script>";
                        this.Page.RegisterStartupScript("aaa", script);
                        //Page.Response.Redirect("FireLinkList.aspx");
                    }
                    else if (type == 3)//save and new
                    {
                        string script = "<script language=javascript>function btnChange_Click(){window.location.href='FireLinkEntry.aspx?action=new'} window.setTimeout(btnChange_Click,150);" + "</script>";
                        this.Page.RegisterStartupScript("aaa", script);
                        //this.Response.Redirect("FireLinkEntry.aspx?action=new");
                    }


                }
                else if (mResult == 2)
                {
                    //time span error, there are some records's event time just out of the new time span
                    this.Alert(this.GetMessage("SOM_FireLinkTimeSpanError"));
                }
                else if (mResult == 3)
                {
                    //can not be absoleted, because there are already some record's using the fireLink
                    this.Alert(this.GetMessage("SOM_FireLinkAbsoleteError"));
                }
                else if (mResult == 10)
                {
                    this.Alert(this.GetMessage("SOM_FireLinkCodeUniqueCheckError"));
                }
                else if (mResult == 11)
                {
                    this.Alert(this.GetMessage("SOM_FireLinkSeqNOUniqueCheckError"));
                }
                else
                {
                    //fail , other reason.
                    this.Alert(this.GetMessage("SaveUnsuccessfully"));

                }
            }
            catch (Exception ex)
            {
                //fail to save or update or absolete
                this.Alert(ex.Message);
            }
        }

        /// <summary>
        /// //Set All Controls Disable.
        /// </summary>
        private void DisableAllControls()
        {
            //this.txtCode.ReadOnly = true;
            //this.txtDetailLocation.ReadOnly = true;
            //this.txtSequenceNO.ReadOnly = true;
            //this.dtbEffectiveFrom.ReadOnly = true;
            //this.dtbEffectiveTo.ReadOnly = true;
            this.txtCode.Enabled = false;
            this.txtDetailLocation.Enabled = false;
            this.txtSequenceNO.Enabled = false;
            this.txtFireLinkCode.Enabled = false;
            //update by gordon 20151030 U273
            //this.txtStation.Enabled = false;
            this.ddlStation.Enabled = false;
            //-------------------------------
            this.dtbEffectiveFrom.Enabled = false;
            this.dtbEffectiveTo.Enabled = false;
            this.ddlLocation.Enabled = false;
            this.ddlLine.Enabled = false;

            //this.btnSave.Enabled = false;
            this.chkObsolete.Enabled = false;
            //this.btnVoid.Enabled = false;
            //this.btnNew.Enabled = false;
            this.btnSave.Enabled = false;
            this.btnSaveAndNew.Enabled = false;
            this.btnSaveAndReturn.Enabled = false;
        }

        #endregion

        protected void btnSaveAndReturn_Click(object sender, EventArgs e)
        {
            this.UpdateRecord(2);
        }

        protected void btnSaveAndNew_Click(object sender, EventArgs e)
        {
            this.UpdateRecord(3);
        }
    }
}
